/**
 * 沈阳万科小程序
 * 
 */


var Dal = require('../../../utils/index.js').Dal
var fs = require('fs')
var uploadMedia = require('../../../utils/uploadMedia.js')

const rmFile = (path) => {
    if (fs.existsSync(path)) {
        fs.unlink(path, function () {
            
        });
    }
}

class SyVanke extends Dal {
    constructor(data) {
        // if(data.create_date) data.create_date = new Date(data.create_date);
        super({ id: data.id }, data, 'xcx_syvanke_activity_0521')
    }

    add(req) {
        if (req.files.img) {
            var imgBuffer = fs.readFileSync(req.files.img.path);
            rmFile(req.files.img.path); // 删除缓存文件
            var url = uploadMedia.uploadImg(imgBuffer, 'xcx_syvanke');
            this.data.img = url;
        }
        return this.sqlHelper.asyncInsert(this.data);
    }
}


module.exports = SyVanke;
